package actions;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JRadioButton;


public class FileChooser extends AbstractAction {

	JFileChooser chooser = null;
	
	private final Component parent;

	private File[] files;

	private JRadioButton setStartTimeZero;

	public FileChooser(Component parent) {
		this.parent = parent;
		chooser = new JFileChooser(new File("."));
		chooser.setMultiSelectionEnabled(true);
		setStartTimeZero = new JRadioButton("Set starttime to zero");
		setStartTimeZero.setSelected(false);
		chooser.setAccessory(setStartTimeZero);
	}
	
	public File[] getFiles() {
		return files;
	}
	
	public boolean isSetStartTimeZero() {
		return setStartTimeZero.isSelected();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		int returnVal = chooser.showOpenDialog(parent);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            files = chooser.getSelectedFiles();
            System.err.println("Fireing ... " + files.length);
            Settings.getInstance().getPropertyChangeSupport().firePropertyChange(Settings.LOAD_GPS_FILES, null, this);
        } else {
        	System.err.println("Problems in the file chooser");
        }
	}

}
